package com.example.frank.login.activity;

import android.app.ActionBar;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.FrameLayout;
import com.example.frank.login.R;

/**
 * Created by Administrator on 2018/5/16.
 */

public class MainActivity extends FragmentActivity implements View.OnClickListener{

    private FrameLayout aFrameLayout,bFrameLayout,cFrameLayout,dFrameLayout;
    private Fragment1 fragment1;
    private Fragment2 fragment2;
    private Fragment3 fragment3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);



        aFrameLayout = (FrameLayout)findViewById(R.id.layout1);
        bFrameLayout = (FrameLayout)findViewById(R.id.layout2);
        cFrameLayout = (FrameLayout)findViewById(R.id.layout3);

        aFrameLayout.setOnClickListener(this);
        bFrameLayout.setOnClickListener(this);
        cFrameLayout.setOnClickListener(this);
        // chickFragment1();

    }

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        switch(arg0.getId()){
            case R.id.layout1:
                chickFragment1();
                break;
            case R.id.layout2:
                chickFragment2();
                break;
            case R.id.layout3:
                chickFragment3();
                break;
        }
    }

    private void chickFragment1(){
        //更改图标
        initImg();
        View image1 = findViewById(R.id.image1);
        Drawable drawable = getResources().getDrawable(R.drawable.pic6_30);
        image1.setBackground(drawable);
        fragment1 = new Fragment1();
        FragmentTransaction fragmentTransaction = this.getSupportFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.frame_content,fragment1);
        fragmentTransaction.commit();


    }

    private void chickFragment2(){

        initImg();
        fragment2 = new Fragment2();
        FragmentTransaction fragmentTransaction = this.getSupportFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.frame_content, fragment2);
        fragmentTransaction.commit();
    }

    private void chickFragment3(){
        initImg();
        View image3 = findViewById(R.id.image3);
        Drawable drawable = getResources().getDrawable(R.drawable.wode_21);
        image3.setBackground(drawable);
        fragment3 = new Fragment3();
        FragmentTransaction fragmentTransaction = this.getSupportFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.frame_content, fragment3);
        fragmentTransaction.commit();
    }

    private void initImg(){
        Drawable drawable1 = getResources().getDrawable(R.drawable.shouye_23);
        Drawable drawable3 = getResources().getDrawable(R.drawable.pic7_30);

        View image1 = findViewById(R.id.image1);
        View image3 = findViewById(R.id.image3);

        image1.setBackground(drawable1);
        image3.setBackground(drawable3);

    }


}
